{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[<model.Issue.Issue object at 0x0000020B21CFF970>, <model.Issue.Issue object at 0x0000020B21CFF940>, <model.Issue.Issue object at 0x0000020B21CFF790>, <model.Issue.Issue object at 0x0000020B21CFF760>]\n"
     ]
    }
   ],
   "source": [
    "issue_no_list = \"\"\"#IAQWHM\n",
    "#IAQV2U\n",
    "#IAQSDK\n",
    "#IAQSD9\"\"\".strip().split(\"\\n\")\n",
    "commit_list = \"\"\"250ae274d632dd28e7c146a19a408d60de3d7c34\n",
    "f04c91d55685d3c8d0000e4b795d18d5114bdeca\n",
    "ee5672b3b37b56e50c226e8fb4b2f0295ed1076f\n",
    "bfcee2cffc5bbe00e5da2df77008ea3eef715ac0\"\"\".strip().split(\"\\n\")\n",
    "\n",
    "import sys\n",
    "sys.path.append('..')\n",
    "import dao.IssueDao as IssueDao\n",
    "import sqlite3\n",
    "issue_list = []\n",
    "with sqlite3.connect(\"../dao/cve_process.db\") as conn:\n",
    "    for issue_no in issue_no_list:\n",
    "        issue_list.append(IssueDao.get_issue(conn, issue_no))\n",
    "print(issue_list)\n",
    "\n",
    "import service.GiteeService as GiteeService\n",
    "for issue, commit in zip(issue_list, commit_list):\n",
    "    # print(issue)\n",
    "    GiteeService.commentOnIssue(issue.targetId, \"https://gitee.com/openharmony/kernel_linux_5.10/commit/{}\".format(commit))\n",
    "# GiteeService.commentOnIssue(issue_no_list, commit_list)\n",
    "# # 同时打印issue_no和commit\n",
    "# for issue_no, commit in zip(issue_no_list, commit_list):\n",
    "#     temp = \"https://gitee.com/openharmony/kernel_linux_5.10/commit/{} ({})\".format(commit, issue_no)\n",
    "#     print(temp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "16\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "sys.path.append('..')\n",
    "import service.CIService as CIService\n",
    "# 重新加载模块\n",
    "import importlib\n",
    "importlib.reload(CIService)\n",
    "resp = CIService.getBranchDetermineInfo('2024/09/22', '2024/10/14')\n",
    "print(len(resp))\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"code\":\"20000\",\"message\":\"请求成功\",\"data\":{\"currentPage\":1,\"dataList\":[{\"id\":1643,\"internalId\":\"OHPSIRT-2024-087621\",\"cveId\":\"CVE-2023-52898\",\"vulnLink\":null,\"repoName\":\"kernel_linux_5.10\",\"versionNum\":\"5.10.165\",\"projectName\":\"openharmony\",\"branch\":\"OpenHarmony-4.0-Release\",\"influence\":null,\"influenceTag\":[],\"processStage\":0,\"investigateTime\":null,\"ownerId\":\"10605821\",\"investigateOwner\":\"ywenrui\",\"issueNo\":null,\"issueLink\":null,\"prLink\":null,\"description\":null,\"createTime\":1726802740018,\"updateTime\":null,\"hangupTime\":null,\"expirationDate\":1727366400000,\"prMergeState\":null,\"prMergeTime\":null},{\"id\":1644,\"internalId\":\"OHPSIRT-2024-084775\",\"cveId\":\"CVE-2024-42312\",\"vulnLink\":null,\"repoName\":\"kernel_linux_5.10\",\"versionNum\":\"5.10.165\",\"projectName\":\"openharmony\",\"branch\":\"OpenHarmony-4.0-Release\",\"influence\":null,\"influenceTag\":[],\"processStage\":0,\"investigateTime\":null,\"ownerId\":\"10605821\",\"investigateOwner\":\"ywenrui\",\"issueNo\":null,\"issueLink\":null,\"prLink\":null,\"description\":null,\"createTime\":1726802747509,\"updateTime\":null,\"hangupTime\":null,\"expirationDate\":1727366400000,\"prMergeState\":null,\"prMergeTime\":null},{\"id\":1645,\"internalId\":\"OHPSIRT-2024-082950\",\"cveId\":\"CVE-2023-52893\",\"vulnLink\":null,\"repoName\":\"kernel_linux_5.10\",\"versionNum\":\"5.10.165\",\"projectName\":\"openharmony\",\"branch\":\"OpenHarmony-4.0-Release\",\"influence\":null,\"influenceTag\":[],\"processStage\":0,\"investigateTime\":null,\"ownerId\":\"10605821\",\"investigateOwner\":\"ywenrui\",\"issueNo\":null,\"issueLink\":null,\"prLink\":null,\"description\":null,\"createTime\":1726802754027,\"updateTime\":null,\"hangupTime\":null,\"expirationDate\":1727366400000,\"prMergeState\":null,\"prMergeTime\":null},{\"id\":1646,\"internalId\":\"OHPSIRT-2024-081458\",\"cveId\":\"CVE-2024-43879\",\"vulnLink\":null,\"repoName\":\"kernel_linux_5.10\",\"versionNum\":\"5.10.165\",\"projectName\":\"openharmony\",\"branch\":\"OpenHarmony-4.0-Release\",\"influence\":null,\"influenceTag\":[],\"processStage\":0,\"investigateTime\":null,\"ownerId\":\"10605821\",\"investigateOwner\":\"ywenrui\",\"issueNo\":null,\"issueLink\":null,\"prLink\":null,\"description\":null,\"createTime\":1726802774892,\"updateTime\":null,\"hangupTime\":null,\"expirationDate\":1727366400000,\"prMergeState\":null,\"prMergeTime\":null},{\"id\":1647,\"internalId\":\"OHPSIRT-2024-098103\",\"cveId\":\"CVE-2024-44969\",\"vulnLink\":null,\"repoName\":\"kernel_linux_5.10\",\"versionNum\":\"5.10.165\",\"projectName\":\"openharmony\",\"branch\":\"OpenHarmony-4.0-Release\",\"influence\":null,\"influenceTag\":[],\"processStage\":0,\"investigateTime\":null,\"ownerId\":\"10605821\",\"investigateOwner\":\"ywenrui\",\"issueNo\":null,\"issueLink\":null,\"prLink\":null,\"description\":null,\"createTime\":1726802781218,\"updateTime\":null,\"hangupTime\":null,\"expirationDate\":1727366400000,\"prMergeState\":null,\"prMergeTime\":null},{\"id\":1648,\"internalId\":\"OHPSIRT-2024-08225\",\"cveId\":\"CVE-2024-43880\",\"vulnLink\":null,\"repoName\":\"kernel_linux_5.10\",\"versionNum\":\"5.10.165\",\"projectName\":\"openharmony\",\"branch\":\"OpenHarmony-4.0-Release\",\"influence\":null,\"influenceTag\":[],\"processStage\":0,\"investigateTime\":null,\"ownerId\":\"10605821\",\"investigateOwner\":\"ywenrui\",\"issueNo\":null,\"issueLink\":null,\"prLink\":null,\"description\":null,\"createTime\":1726802806510,\"updateTime\":null,\"hangupTime\":null,\"expirationDate\":1727366400000,\"prMergeState\":null,\"prMergeTime\":null},{\"id\":1649,\"internalId\":\"OHPSIRT-2024-087357\",\"cveId\":\"CVE-2024-43834\",\"vulnLink\":null,\"repoName\":\"kernel_linux_5.10\",\"versionNum\":\"5.10.165\",\"projectName\":\"openharmony\",\"branch\":\"OpenHarmony-4.0-Release\",\"influence\":null,\"influenceTag\":[],\"processStage\":0,\"investigateTime\":null,\"ownerId\":\"10605821\",\"investigateOwner\":\"ywenrui\",\"issueNo\":null,\"issueLink\":null,\"prLink\":null,\"description\":null,\"createTime\":1726802813105,\"updateTime\":null,\"hangupTime\":null,\"expirationDate\":1727366400000,\"prMergeState\":null,\"prMergeTime\":null},{\"id\":1650,\"internalId\":\"OHPSIRT-2024-082444\",\"cveId\":\"CVE-2024-43830\",\"vulnLink\":null,\"repoName\":\"kernel_linux_5.10\",\"versionNum\":\"5.10.165\",\"projectName\":\"openharmony\",\"branch\":\"OpenHarmony-4.0-Release\",\"influence\":null,\"influenceTag\":[],\"processStage\":0,\"investigateTime\":null,\"ownerId\":\"10605821\",\"investigateOwner\":\"ywenrui\",\"issueNo\":null,\"issueLink\":null,\"prLink\":null,\"description\":null,\"createTime\":1726802820303,\"updateTime\":null,\"hangupTime\":null,\"expirationDate\":1727366400000,\"prMergeState\":null,\"prMergeTime\":null},{\"id\":1651,\"internalId\":\"OHPSIRT-2024-083565\",\"cveId\":\"CVE-2022-48896\",\"vulnLink\":null,\"repoName\":\"kernel_linux_5.10\",\"versionNum\":\"5.10.165\",\"projectName\":\"openharmony\",\"branch\":\"OpenHarmony-4.0-Release\",\"influence\":null,\"influenceTag\":[],\"processStage\":0,\"investigateTime\":null,\"ownerId\":\"10605821\",\"investigateOwner\":\"ywenrui\",\"issueNo\":null,\"issueLink\":null,\"prLink\":null,\"description\":null,\"createTime\":1726802851065,\"updateTime\":null,\"hangupTime\":null,\"expirationDate\":1727366400000,\"prMergeState\":null,\"prMergeTime\":null},{\"id\":1652,\"internalId\":\"OHPSIRT-2024-093046\",\"cveId\":\"CVE-2024-44965\",\"vulnLink\":null,\"repoName\":\"kernel_linux_5.10\",\"versionNum\":\"5.10.165\",\"projectName\":\"openharmony\",\"branch\":\"OpenHarmony-4.0-Release\",\"influence\":null,\"influenceTag\":[],\"processStage\":0,\"investigateTime\":null,\"ownerId\":\"10605821\",\"investigateOwner\":\"ywenrui\",\"issueNo\":null,\"issueLink\":null,\"prLink\":null,\"description\":null,\"createTime\":1726802859284,\"updateTime\":null,\"hangupTime\":null,\"expirationDate\":1727366400000,\"prMergeState\":null,\"prMergeTime\":null}],\"pageSize\":10,\"totalSize\":16}}'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "headers = {\n",
    "    \"Cookie\" : \"token=BQCVAZJ6fPDSWPre8wJSRBTZ/k7/OgV5/ToFCdsFhlbcesn2O7JImDxtvxMMgh3AQZeGCz9ksw9KvMa+q8yCyLWYib42jVRsiujuIj2/ScQazfaQ0gFFFGRIfaviHQQotbyZ9vOyfM/N3G8Nov/KfAl9cTo2h2BIJZT8MNOZCSkXOK8NZg5AmNau0pbvzaEjyK0D+xM/N7p39rGNWqao4fCbT2EeTOlK+nW8GkeQ0QTr6chIkMfF1pOoMkXtyFhDirafcIP/pfSq1mGm4c+IQQ4By+niOURiP/bST1BJYU/UyQKPpSzgRUKMrnoFkoALzo9leHLOAIuJmzAhhTnldcWoBQCbtT0UzqBTTPSw6ZWLMqdL9ORbC+mNhxPzjtOwnAWdWv7aRs5Nxbi38NUJjl8Zj8SuptYcd/VcDUOMO8Faq9UnbHN4jAcUht6trrszpEwycTLXbozHfqO9LWX14ic3y+QNDaWJJk+X4qT7HZPbZjVhYzNkMjktODg1MC00MDNmLWE3NjgtMmJhMzhhMWRmYjViAAAAACMiISAfHh0cGxoZGBcWFRQTEhEQDw4NDAsKCQgHBgUEAwIBnu/TMdJR1Dj0+6fRpT3w58YiVhDh3lODkPZ8kTKMLvQ=; _frid=8a21010d7fed4ed2ab3bc98785758bc8; HWWAFSESID=0fc15768f23e744065; HWWAFSESTIME=1725516636873; _fr_ssid=f96a85c03bce4f8c9d2bb06d14512672; _fr_pvid=04ce5cbbefae42c084c0528dcd17dd26\"\n",
    "}\n",
    "# headers['Content-Type'] = 'application/json;charset=UTF-8'\n",
    "data = {\n",
    "    \"internalId\": None,\n",
    "    \"cveId\": None,\n",
    "    \"repoName\": None,\n",
    "    \"versionNum\": None,\n",
    "    \"branch\": None,\n",
    "    \"influence\": None,\n",
    "    \"processStage\": 0,\n",
    "    \"investigateTime\": None,\n",
    "    \"createTime\": None,\n",
    "    \"investigateOwner\": None,\n",
    "    \"startInvestigateTime\": None,\n",
    "    \"endInvestigateTime\": None,\n",
    "    \"startCreateTime\": None,\n",
    "    \"endCreateTime\": None,\n",
    "    \"updateTime\": None,\n",
    "    \"sortField\": \"\",\n",
    "    \"sortType\": \"DESC\",\n",
    "    \"type\": 0,\n",
    "    \"startExpirationDate\": 1727136000000,\n",
    "    \"endExpirationDate\": 1728864000000,\n",
    "    \"pageSize\": 10,\n",
    "    \"currentPage\": 1,\n",
    "    \"totalSize\": 34\n",
    "}\n",
    "requests.post('https://ci.openharmony.cn/api/opensoftware/vulnerability/investigate/about_me', headers=headers,json=data).text\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'{\"code\":\"20000\",\"message\":\"请求成功\",\"data\":null}'"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import sys\n",
    "import json\n",
    "import pprint\n",
    "sys.path.append('..')\n",
    "import service.CIService as ciService\n",
    "\n",
    "def make_opration_data(analyzeId, processStage, cvssvBasescore, cvssvVector, analyzeReason):\n",
    "    if analyzeReason is None or analyzeReason == '':\n",
    "        raise ValueError(\"analyzeReason is empty\")\n",
    "    operation_data = {\n",
    "        \"analyzeId\": int(analyzeId),\n",
    "        \"processStage\": int(processStage),\n",
    "        \"type\": 1,\n",
    "        \"vulnerabilityType\": 4,\n",
    "        \"cvssvBasescore\": float(cvssvBasescore),\n",
    "        \"cvssvVector\": str(cvssvVector),\n",
    "        \"cwe\": \"\",\n",
    "        \"reviewResult\": 0,\n",
    "        \"analyzeReason\": str(analyzeReason)\n",
    "    }\n",
    "    return operation_data\n",
    "def get_analyzeInfo(cve_id):\n",
    "    respText = ciService._searchCVE('https://ci.openharmony.cn/api/opensoftware/vulnerability/analyze/2', cve_id)\n",
    "    j = json.loads(respText)\n",
    "    if str(j['code']) != '20000':\n",
    "        raise RuntimeError(\"cve_id {} , search_error: {}\".format(cve_id, j['message']))\n",
    "    else :\n",
    "        if j['data']['totalSize'] != 1:\n",
    "            raise RuntimeError(\"{} not found\".format(cve_id))\n",
    "        else :\n",
    "            internalId= ciService._getInternalId(j)\n",
    "            headers = {\n",
    "                \"Cookie\" : \"token=BQCTAdlus3jTCBmX+SUNOhot+3/vLjTlgL7zW+IZtbUPYUaHPKU0Xl3mjjpQI7hqk+GeUTA8lizf5FeASRsH1yH1dCACKrJv0JUpKq8g2QH/0izQBRZ+SOYbnAp8ojjOuXmOAE3b89ADfKTZCn5kWFE8sC+wraFevgbkZtru1vbid16xn4rhwbkbwXaIgpVBSCAKEYqww6tj+j0pdldstG7LrPsrpdXqt1bdjmch0rqn2LkUZJUX062xR05h4UGInJk57eTLISRu/wL1w8fGaSMo1458fT81x1081A7qJX3jVtRc9/qrDkKsKG5iGNvQK4ARKkTK761EkSPqUca/Og1g9VPGWNjfP0KFIwJtnetSaK4g+zeCg7aUjqKUmTRwsw4aNkTk+qG1WVTVvvRF3h74exorY8V27h5ZOGkoG74wL35jESrV7UKoj0ZXY3+eP5QhzAiR1KVc7kQgWh2ANrdhbAsMBHjBCFhPgYSW/2Y1YWMzZDI5LTg4NTAtNDAzZi1hNzY4LTJiYTM4YTFkZmI1YgAAAAAVFBMSERAPDg0MCwoJCAcGBQQDAgE60anMsYeHeDJYv2ZB/GT7wsRZZmQoxySTXWKdowo/fA==; _frid=8a21010d7fed4ed2ab3bc98785758bc8; HWWAFSESID=0fc15768f23e744065; HWWAFSESTIME=1725516636873; _fr_ssid=53a3007e3f5f4dccbb1f4b22f9151ebc; _fr_pvid=28bc6b8c710e454cbce066a3739bcf44\",\n",
    "                        \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3\",     \n",
    "            }\n",
    "            import requests\n",
    "            resp = requests.get('https://ci.openharmony.cn/api/opensoftware/vulnerability/analyze/'+internalId, headers=headers)\n",
    "            #json pretty print\n",
    "            analyzeInfo = json.loads(resp.text)\n",
    "            if analyzeInfo['code'] != '20000':\n",
    "                print(\"cve_id {} analyze_error: {}\".format(cve_id, analyzeInfo['message']))\n",
    "            return analyzeInfo['data']\n",
    "def do_opration(data):\n",
    "    resp = requests.post('https://ci.openharmony.cn/api/opensoftware/vulnerability/analyze/operation',\n",
    "                  headers=headers, json=data)\n",
    "    if json.loads(resp.text)['code'] != '20000':\n",
    "        raise RuntimeError(\"{} 请求失败\", data)\n",
    "    return resp\n",
    "\n",
    "# 从漏洞分析阶段进入到专家审核阶段，拒绝类型为误报\n",
    "def refuse_cve(cve_id, cve_refuse_reason):\n",
    "    analyzeInfo = get_analyzeInfo(cve_id)['analyze']\n",
    "    # pprint.pprint(analyzeInfo)\n",
    "    analyzeId = analyzeInfo['id']\n",
    "    processStage = analyzeInfo['processStage']\n",
    "    vulnerabilityType = analyzeInfo['vulnerabilityType']\n",
    "    cvssvBasescore = analyzeInfo['cvssvBasescore']\n",
    "    cvssvVector = analyzeInfo['cvssvVector']\n",
    "    operation_data = make_opration_data(analyzeId=analyzeId, processStage=processStage, \n",
    "                                        cvssvBasescore=cvssvBasescore, cvssvVector=cvssvVector, analyzeReason=cve_refuse_reason)\n",
    "    return do_opration(operation_data)\n",
    "refuse_cve('CVE-2024-42144', '主线版本引入问题补丁为f5f633b18234cecb0e6ee6e5fbb358807dda15c3(thermal/drivers/mediatek: Add the Low Voltage Thermal Sensor driver)，该版本未合入此补丁，因此不涉及此漏洞').text"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
